﻿<link href="../../Content/themes/default/uploadImg.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery/jquery-1.4.4.js" type="text/javascript"></script>
<script src="../../Scripts/ajaxupload.3.6.js" type="text/javascript"></script>

@model Enter.Mvc.Mall.Model.UploadModel
<script type="text/javascript">


    $(document).ready(function () {

        var button = $('#button_upload'), interval;
        var showimg = $('#@Model.imgID.ToString()');
        var msg = $('#@Model.msg.ToString()');
        var hfUrl = $('#@Model.hfImgUrl.ToString()');
        new AjaxUpload(button, {
            //  '/Common/Upload /Handler/AjaxuploadHandler.ashx
            action: '/Common/Upload?imgtype=@Model.imgType.ToString()', 
            onSubmit: function (file, ext) {

                if (!(ext && /^(gif|jpg|jpeg|png)$/.test(ext[0].toLocaleLowerCase()))) {
                    msg.html('图片格式不正确,请选择 gif|jpg|jpeg|png 格式的文件!');
                    return false;
                }

                // change button text, when user selects file
                button.text('上传中');
                this.disable();

                // Uploding -> Uploading. -> Uploading...
                interval = window.setInterval(function () {
                    var text = button.text();
                    if (text.length < 10) {
                        button.text(text + '.');
                    } else {
                        button.text('上传中');
                    }
                }, 200);

            },
            onComplete: function (file, response) {
                window.clearInterval(interval);
                
                // enable upload button
                button.text('上传完成');
                this.enable();
 
                var returnStr = response.replace("<PRE>", "").replace("</PRE>", "").replace("<pre>", "").replace("</pre>", "");
                var str = returnStr.split('|');
                if (str[0]=="00")
                {
                    showimg.attr("src", str[1].replace('-',''));

                    hfUrl.val(str[1].split('-')[1]);
                }
                else{
                    msg.html(str[1]);
                }
              
            }
        });
    }); </script>
<div class="upload">


    <div id="button_upload" class="upload-btn">
        <em>上传图片</em>
    </div>
</div>

   